import 'package:azlistview/azlistview.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/language/language_util.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

import 'area_model.dart';
import 'controller.dart';

class AreaListView extends BaseGetView<AreaListController> {
  @override
  String get title => AppLanguageUtil.to.countryCodeNavTitle;

  @override
  Color? get barBackgroundColor => Colors.black;

  @override
  Widget? get backView => CommonWidgets.appBarLeading();

  @override
  Widget buildBody(BuildContext context) {
    return Obx(
      () => Container(
        color: Colors.black,
        child: AzListView(
          data: controller.cityList,
          itemCount: controller.cityList.length,
          itemBuilder: (BuildContext context, int index) {
            AreaModel model = controller.cityList[index];
            return getListItem(context, model);
          },
          padding: EdgeInsets.zero,
          susItemBuilder: (BuildContext context, int index) {
            AreaModel model = controller.cityList[index];
            String tag = model.getSuspensionTag();
            return getSusItem(context, tag);
          },
          indexBarData: const [...kIndexBarData],
        ),
      ),
    );
  }

  /// 列表
  static Widget getListItem(BuildContext context, AreaModel model) {
    return ListTile(
      title: Text(model.name!),
      trailing: Text('+${model.code}'),
      contentPadding: const EdgeInsets.fromLTRB(
          15, 0, 32, 0), //EdgeInsets.symmetric(horizontal: 15),
      onTap: () {
        Get.back(result: model.code);
      },
    );
  }

  /// 顶部字母A-Z导航
  static Widget getSusItem(BuildContext context, String tag,
      {double susHeight = 40}) {
    return Container(
      height: susHeight,
      width: MediaQuery.of(context).size.width,
      padding: const EdgeInsets.only(left: 16.0),
      color: const Color(0xFF1C1C21),
      alignment: Alignment.centerLeft,
      child: Text(
        tag,
        softWrap: false,
        style: const TextStyle(
          fontSize: 14.0,
          color: Color(0xFF666666),
        ),
      ),
    );
  }
}
